import request from '@/utils/request';
import type { BaseBeanModel, ResponsePageData, ResponseBaseData, QueryParamModel } from '@/api/model/baseModel';

const basePath = '/bpm/bpm';

/** 流程监控 */
export interface SysBpmMonitorDto extends BaseBeanModel {
  /** 流程实例id */
  entryid?: string;
  /** 流程实例名称 */
  entryname?: string;
  /** 流程定义名称 */
  definename?: string;
  /** 流程状态 */
  state?: string;
  /** 启动时间 */
  startdate?: any;
  startDateBegin?: any;
  startDateEnd?: any;
  /** 结束时间 */
  enddate?: any;
  /** 创建者 */
  userId?: string;
  /** 是否运行实例 */
  isRunning?: number;
}

/**
 * 获取流程实例分页数据
 * @param param 查询参数
 * @returns 流程实例分页数据
 */
export function listProcessInstanceByPage(param: QueryParamModel): Promise<ResponsePageData<SysBpmMonitorDto>> {
  return request.post(`${basePath}/monitor/getPrcessInstListByPage/v1`, param);
}

/**
 * 挂起流程实例
 * @param processInstanceId 流程实例id
 * @returns 挂起流程实例结果
 */
export function suspendProcess(processInstanceId: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/bpmConsoleAction/supProcessEntry/v1`, { processInstanceId });
}

/**
 * 恢复流程实例
 * @param processInstanceId 流程实例id
 * @returns 恢复流程实例结果
 */
export function recoverProcess(processInstanceId: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/bpmConsoleAction/recoverProcessEntry/v1`, { processInstanceId });
}

/**
 * 删除流程实例
 * @param processInstanceId 流程实例id
 * @returns 删除流程实例结果
 */
export function deleteProcess(processInstanceId: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/bpmConsoleAction/deleteProcessEntry/v1`, { processInstanceId });
}

/**
 * 仅删除流程实例。不删除业务实例
 * @param entryIds 流程实例id
 * @returns 仅删除流程实例结果
 */
export function deleteProcessPart(entryIds: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/monitor/deleteProcessEntryPart/v1`, { entryIds });
}

/**
 * 终止流程实例
 * @param processInstanceId 流程实例id
 * @returns 终止流程实例结果
 */
export function endProcess(param: { executionId: string; message: string }): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/monitor/doend/v1`, param);
}

/**
 * 复活流程实例
 * @param param 流程实例信息
 * @returns 复活流程实例结果
 */
export function reviveProcess(param: {
  dto1: string;
  dto2: string;
  dto3: string;
  dto4: string;
}): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/monitor/reviveProcess/v1`, param);
}

/**
 * 获取流程实例分页数据
 * @param param 查询参数
 * @returns 流程实例分页数据
 */
export function listProcessEntryTodoList(param: QueryParamModel): Promise<ResponsePageData<any>> {
  return request.post(`${basePath}/monitor/getProcessEntryTodoList/v1`, param);
}

/**
 * 删除执行人
 * @param param 执行人信息
 * @returns 删除结果
 */
export function deletePerformer(param: {
  userIds: string;
  executionId: string;
  processInstanceId: string;
}): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/bpmConsoleAction/doDeleteProcessTask/v1`, param);
}

/**
 * 删除传阅人
 * @param param 传阅人信息
 * @returns 删除结果
 */
export function deleteReaderOrTransfer(param: {
  processInstanceId: string;
  taskId: string;
}): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/monitor/deleteHistoryTask/v1`, param);
}

/**
 * 获取流程变量数据
 * @param param 查询参数
 * @returns 流程变量数据
 */
export function listProcessEntryVars(param: {
  processInstanceId: string;
  keyWord: string;
}): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/monitor/getProcessEntryVariable/v1`, param);
}

/**
 * 获取异常信息分页数据
 * @param param 查询参数
 * @returns 异常信息分页数据
 */
export function listProcessExceptionListByPage(param: QueryParamModel): Promise<ResponsePageData<any>> {
  return request.post(`${basePath}/monitor/getProcessExceptionListByPage/v1`, param);
}

/**
 * 获取异常详细信息
 * @param id 流程实例id
 * @returns 异常详细信息
 */
export function getProcessExceptionById(id: string): Promise<ResponseBaseData<any>> {
  return request.get(`${basePath}/monitor/getProcessExceptionById/${id}/v1`);
}

/**
 * 删除异常流程实例
 * @param dbId 流程实例id
 * @returns 删除异常流程实例结果
 */
export function deleteException(dbId: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/monitor/deleteProcessException/v1`, { dbId });
}
